import unittest
from parameterized import parameterized
from api.miaoce_login import miaoce_Login
import json
from app import Base_Dir

alist = []


def build_data():
    with open(str(Base_Dir) + r"\data\user_pwd.txt", "r") as f:
        res = f.read()
        dic_res = json.loads(res)
        for i in dic_res.get('data'):
            new_tuple = (i.get('username'), i.get('password'), i.get('result'))

            alist.append(new_tuple)
        # print(alist)
        # build_data()

        return alist


class TestCaseLogin(unittest.TestCase):
    @parameterized.expand(
        build_data())
    def testLogin(self, data_user, data_pass, result):
        res = miaoce_Login(data_username=data_user, data_pwd=data_pass)
        try:
            self.assertEqual(int(res.get('result')), result)
        except AssertionError as e:
            raise


if __name__ == '__main__':
    unittest.main()
